{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from pandas import Series,DataFrame\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-1.285713</td>\n",
       "      <td>0.637658</td>\n",
       "      <td>0.274951</td>\n",
       "      <td>0.425842</td>\n",
       "      <td>-1.272870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.365454</td>\n",
       "      <td>1.425270</td>\n",
       "      <td>-0.903013</td>\n",
       "      <td>0.824343</td>\n",
       "      <td>0.877543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.634962</td>\n",
       "      <td>-0.954580</td>\n",
       "      <td>0.510909</td>\n",
       "      <td>1.930947</td>\n",
       "      <td>0.297301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-2.108159</td>\n",
       "      <td>-0.204559</td>\n",
       "      <td>0.525155</td>\n",
       "      <td>0.151102</td>\n",
       "      <td>-1.640471</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4\n",
       "0 -1.285713  0.637658  0.274951  0.425842 -1.272870\n",
       "1  0.365454  1.425270 -0.903013  0.824343  0.877543\n",
       "2 -0.634962 -0.954580  0.510909  1.930947  0.297301\n",
       "3 -2.108159 -0.204559  0.525155  0.151102 -1.640471"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=DataFrame(np.random.randn(20).reshape((4,5)))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-1.29</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0.27</td>\n",
       "      <td>0.43</td>\n",
       "      <td>-1.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.37</td>\n",
       "      <td>1.43</td>\n",
       "      <td>-0.90</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.63</td>\n",
       "      <td>-0.95</td>\n",
       "      <td>0.51</td>\n",
       "      <td>1.93</td>\n",
       "      <td>0.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-2.11</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>0.53</td>\n",
       "      <td>0.15</td>\n",
       "      <td>-1.64</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       0      1      2     3      4\n",
       "0  -1.29   0.64   0.27  0.43  -1.27\n",
       "1   0.37   1.43  -0.90  0.82   0.88\n",
       "2  -0.63  -0.95   0.51  1.93   0.30\n",
       "3  -2.11  -0.20   0.53  0.15  -1.64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f=lambda x: '%.2f'  %x\n",
    "df.applymap(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.35</td>\n",
       "      <td>1.391579</td>\n",
       "      <td>0.422506</td>\n",
       "      <td>-1.73</td>\n",
       "      <td>-0.919807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.12</td>\n",
       "      <td>-1.143692</td>\n",
       "      <td>0.031095</td>\n",
       "      <td>-1.91</td>\n",
       "      <td>0.837703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.66</td>\n",
       "      <td>-0.300108</td>\n",
       "      <td>0.137259</td>\n",
       "      <td>0.19</td>\n",
       "      <td>0.566565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.11</td>\n",
       "      <td>-0.766495</td>\n",
       "      <td>0.854755</td>\n",
       "      <td>-2.53</td>\n",
       "      <td>0.859428</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       0         1         2      3         4\n",
       "0   0.35  1.391579  0.422506  -1.73 -0.919807\n",
       "1  -0.12 -1.143692  0.031095  -1.91  0.837703\n",
       "2  -0.66 -0.300108  0.137259   0.19  0.566565\n",
       "3  -0.11 -0.766495  0.854755  -2.53  0.859428"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[3]=df[3].apply(f)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.35</td>\n",
       "      <td>1.391579</td>\n",
       "      <td>0.422506</td>\n",
       "      <td>-1.73</td>\n",
       "      <td>-0.919807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.12</td>\n",
       "      <td>-1.143692</td>\n",
       "      <td>0.031095</td>\n",
       "      <td>-1.91</td>\n",
       "      <td>0.837703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.66</td>\n",
       "      <td>-0.300108</td>\n",
       "      <td>0.137259</td>\n",
       "      <td>0.19</td>\n",
       "      <td>0.566565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.11</td>\n",
       "      <td>-0.766495</td>\n",
       "      <td>0.854755</td>\n",
       "      <td>-2.53</td>\n",
       "      <td>0.859428</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       0         1         2      3         4\n",
       "0   0.35  1.391579  0.422506  -1.73 -0.919807\n",
       "1  -0.12 -1.143692  0.031095  -1.91  0.837703\n",
       "2  -0.66 -0.300108  0.137259   0.19  0.566565\n",
       "3  -0.11 -0.766495  0.854755  -2.53  0.859428"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xx                  ————————       +20————————\n"
     ]
    }
   ],
   "source": [
    "b = \"%(name)-20s————————%(age)+10d————————\"%{'name':'xx','age':20}\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
